/**
 * 显示消息提示框
 * @param content 提示的标题
 */

import {
	isNull
} from "./validate";

let createUserNameList = []
let corolList = [

	{
		value: 2,
		label: "绿色",
		color: "#ecffe5",
	},
	{
		value: 4,
		label: "黄色",
		color: "#f5ebbc"
	},
	{
		value: 0,
		label: "红色",
		color: "#ffcccc"
	},

	{
		value: 1,
		label: "蓝色",
		color: "#c8e5ff"
	},
	{
		value: 5,
		label: "紫色",
		color: "#f5cbff",
	},
	{
		value: 3,
		label: "灰色",
		color: "#aba9a9"
	},

	{
		value: 9,
		label: "无色",
		color: "#fff"
	},
]




export function formattersysClassroomName(uid) {
	let createUserNameList = getcommon('sysClassroomList')
	for (var x = 0; x < createUserNameList.length; x++) {
		if (createUserNameList[x].id == uid) {
			return createUserNameList[x].name;
		}
	}
}

export function shijianduanaa(uid) {
	let createUserNameList = getcommon('createUserNameList')
	for (var x = 0; x < createUserNameList.length; x++) {
		if (createUserNameList[x].id == uid) {
			return (
				createUserNameList[x].startTime + "-" + createUserNameList[x].outTime
			);
		}
	}
}

export function getShiJianDuanById(uid) {
	let shijianduanList = getcommon('shijianduan')
	for (var x = 0; x < shijianduanList.length; x++) {
		if (shijianduanList[x].id == uid) {
			return (
				shijianduanList[x].startTime + "-" + shijianduanList[x].outTime
			);
		}
	}
}
export let evaluationPlan = {
	type: "",
	erid: 0,
	axStudentDO: {
		age2: 0,
	},
	axParentsDO: {
		phone: "",
	},
	gtQtphg: "-1", //"",
	gtBtj: "-1", //"本体觉",
	gtCjfyj: "-1", //"触觉防御觉",

	fyDyd: "-1", //"发育大运动",
	fyJxyd: "-1", //"发育精细运动",
	fySynl: "-1", //"发育适应能力",
	fyYybd: "-1", //"发育语言表达",
	fySjxw: "-1", //"发育社交行为",

	fyQlbf: "-1", //"发育全量表分",
	fyZl: "-1", //"发育智龄",
	fyFys: "-1", //"发育发育商",

	jcydnlStphkz: "-1", //"运动身体平衡控制",
	jcydnlZtxtx: "-1", //"运动肢体协调度",
	jcydnlStnl: "-1", //"运动身体耐力",
	jcydnlZtbfk: "-1", //"运动肢体爆发力",
	//旋转
	byydtbxz: "-1", //"0",
	djzZ: "-1", //"单脚站左",
	djzY: "-1", //"单脚站右",
	byydtb1: "-1", //"1分钟是否坚持完成",
	dzsfbz: "-1", //"动作是否标准",
	stsfpy: "-1", //"身体是否偏移",
	ldty: "-1", //"立定跳远",

	tgdss: "-1", //"听广度顺数",
	tgdfspy: "-1", //"拼音仿说",
	tgdjzfs: "-1", //0,

	tfbljty: "-1", //"累计听音",
	tfbcw: "-1", //"错误",
	tjyds: "-1", //"倒数",
	jzfstwwtsl: "-1", //"问题数量",
	jzfstwcwsl: "-1", //"错误数量 ",
	sfbyhd: "-1", //"应划掉",
	sfbhc: "-1", //"0",//划错x
	sfbhl: "-1", //"划漏",
	sfbsgdwcl: "-1", //"视广度完成率",
	sfbsdthnl: "-1", //"视动统合能力",

	sfbsdsd: "-1", //"抄写个数",
	sfbcw: "-1", //"错误",
	swswfs: "-1", //"思维分数",
	swbfb: "-1", //"百分比",
	swiq: "-1", //"iq",

	//xs
	kdwwtsl: "-1", //"看短文问题数量",
	kdwcwsl: "-1", //"看短文错误数量",
	ydsj: "-1", //"阅读时间",
	ydzs: "-1", //"阅读字数",
	yctjzwtsl: "-1", //"延迟听句子问题数量",
	yctjzcwsl: "-1", //"延迟听句子错误数量",
	ydnlts: "-1", //"跳顺",
	chandlh: "-1", //"错划漏划",

	tzjnlTgd: "-1", //"听知觉听广度",
	tzjnlTfbswl: "-1", //"听知觉听分辨失误率",
	tzjnlTjy: "-1", //"听知觉听记忆",
	tzjnlTljzql: "-1", //"听知觉听理解正确率",
	tzjnlTjyzql: "-1", //"听知觉听记忆准确率",
	szjnlSfbswl: "-1", //"视动分辨失误率",
	szjnlSgd: "-1", //"视动视广度",
	szjnlSdzhnl: "-1", //"视动综合能力",
	szjnlSdsu: "-1", //"视动速度",
	ydljnlYdsu: "-1", //"阅读理解阅读速度",
	ydljnlYdljzql: "-1", //"阅读理解准确率",
	swnlSwfs: "-1", //"思维分数",
	swnlBfdj: "-1", //"思维百分比等级",
	swnlIq: "-1", //"思维IQ",
	student: {
		sex: "",
		id: "0",
		age2: "",
		height: "",
		weight: "",
		name: "0",
		dateOfBirth: "",
	},
	lishi: "",
}

export let LessonPreparationRecordsTypeList = [

	//感统课
	{
		id: null,
		title: "静态引入",
		code: "jt",
		titleindexOf: [],
		age: "",
		value: "选择",
		offlineClassName: ["4", "12"]
	},
	{
		id: null,
		title: "热身1",
		code: "rs1",
		titleindexOf: [],
		age: "",
		value: "选择",
		offlineClassName: ["4", "12"]
	},

	{
		id: null,
		title: "热身2",
		code: "rs2",
		titleindexOf: [],
		age: "",
		value: "选择",
		offlineClassName: ["4", "12"]
	},
	{
		id: null,
		title: "静态1",
		code: "jcjingtai1",
		titleindexOf: ["基础身体控制", "基础视觉控制"],
		age: 1,
		value: "选择",
		offlineClassName: ["3", "5", "11", "13"]
	},


	{
		id: null,
		title: "静态2",
		code: "jcjingtai2",
		titleindexOf: ["基础身体控制", "基础视觉控制"],
		age: 1,
		value: "选择",
		offlineClassName: ["3", "5", "11", "13"]
	},


	{
		id: null,
		title: "主体1",
		code: "xlzt1",
		titleindexOf: [],
		age: 1,
		value: "选择",
		offlineClassName: ["3", "5", "11", "4", "12", "13"]
	},
	{
		id: null,
		title: "主体2",
		code: "xlzt2",
		titleindexOf: [],
		age: 1,
		value: "选择",
		offlineClassName: ["3", "5", "11", "4", "12", "13"]
	},
	{
		id: null,
		title: "主体3",
		code: "xlzt3",
		titleindexOf: [],
		age: 1,
		value: "选择",
		offlineClassName: ["3", "5", "11", "4", "12", "13"]
	},
	{
		id: null,
		title: "主体4",
		code: "xlzt4",
		titleindexOf: [],
		age: null,
		value: "选择",
		offlineClassName: ["3", "5", "11", "13"]
	},

	{
		id: null,
		title: "听动/视动1",
		code: "jctdsd1",
		titleindexOf: [],
		age: "7,30",
		value: "选择",
		offlineClassName: ["3", "5", "11", "13"]
	},
	{
		id: null,
		title: "听动/视动2",
		code: "jctdsd2",
		titleindexOf: [],
		age: "7,30",
		value: "选择",
		offlineClassName: ["3", "5", "11", "13"]
	},
	{
		id: null,
		title: "进阶1",
		code: "jcjj1",
		titleindexOf: [],
		age: "7,30",
		value: "选择",
		offlineClassName: ["3", "5", "11", "13"]
	},
	{
		id: null,
		title: "进阶2",
		code: "jcjj2",
		titleindexOf: [],
		age: "7,30",
		value: "选择",
		offlineClassName: ["3", "5", "11", "13"]
	},
	// {
	//   id: null,
	//   title: "听动/视动",
	//   code: "jctdsd1",
	//   titleindexOf: [],
	//   age: "5,8",
	//   value: "选择",
	//   offlineClassName: ["3", "5", "11"]
	// },
	//认知情商
	// {
	//   id: null,
	//   title: "认知情商备课",
	//   code: "",
	//   titleindexOf: [],
	//   age: null,
	//   value: "点击备课",
	//   offlineClassName: ["2"]
	// },


	{
		id: null,
		title: "互动",
		code: "hudong",
		titleindexOf: [],
		age: "0,4",
		value: "选择",
		offlineClassName: ["4", "12"]
	},
	{
		id: null,
		title: "补充",
		code: "bcxm",
		titleindexOf: [],
		value: "输入",
		offlineClassName: ["4", "12", "3", "5", "11", "13"]
	}
]
let isShowLoading = false
let isShowToast = false
export function toast(content, icon = 'none') {
	isShowToast = true
	uni.showToast({
		icon: icon,
		title: content,
		duration: 1000,
	})

	// 定时器，1500 毫秒后执行
	setTimeout(() => {
		// 在这里写需要延迟执行的代码
		isShowToast = false
	}, 1000);

}


export function showLoading(content = '加载中') {

	if (isShowToast) {
		console.log("toast运行中");
		return
	}
	isShowLoading = true
	uni.showLoading({
		title: content
	})


}
export function hideLoading() {
	isShowLoading = false
	uni.hideLoading()
}



export function getColorByCode(code) {
	if (code == null) {
		return '#fff'
	}
	for (let s of corolList) {
		if (s.code == code) {
			return s.color
		}
	}
}

/**
 * 显示模态弹窗
 * @param content 提示的标题
 */
export function showConfirm(content, isOk = true) {
	return new Promise((resolve, reject) => {
		uni.showModal({
			title: '提示',
			content: content,
			cancelText: '取消',
			showCancel: isOk,

			confirmText: '确定',
			success: function(res) {
				resolve(res)
			}
		})
	})
}

/**
 * 参数处理
 * @param params 参数
 */
export function tansParams(params) {
	let result = ''
	for (const propName of Object.keys(params)) {
		const value = params[propName]
		var part = encodeURIComponent(propName) + "="
		if (value !== null && value !== "" && typeof(value) !== "undefined") {
			if (typeof value === 'object') {
				for (const key of Object.keys(value)) {
					if (value[key] !== null && value[key] !== "" && typeof(value[key]) !== 'undefined') {
						let params = propName + '[' + key + ']'
						var subPart = encodeURIComponent(params) + "="
						result += subPart + encodeURIComponent(value[key]) + "&"
					}
				}
			} else {
				result += part + encodeURIComponent(value) + "&"
			}
		}
	}
	return result
}

/**
 * 头像处理方法 data 是学生
 * @param {Object} data
 */
export function pictureProcessing(data) {

	if (data == null) {
		return "https://api3.m.grasswave.cn/opsli-boot/resources/static/files/img/boy.png";
	}
	if (data.sex == 1 && (data.imageUrl == null || data.imageUrl == "")) {
		return "https://api3.m.grasswave.cn/opsli-boot/resources/static/files/img/boy.png";
	}

	if ((data.sex == 0 && data.imageUrl == null) || data.imageUrl == "") {
		return "https://api3.m.grasswave.cn/opsli-boot/resources/static/files/img/girl.png";
	}

	return data.imageUrl;
}


export function formatterUserName(uid) {

	let asdf = getcommon('createUserNameList')

	for (var x = 0; x < asdf.length; x++) {
		if (asdf[x].id == uid) {
			return asdf[x].realName;
		}
	}
}


/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 获取common 中的常用数
 * @param commonFind 字段
 * @returns {void|*}
 */
export function getcommon(commonFind) {
	try {
		if (commonFind == null) {
			return [];
		}
		let asdf = JSON.parse(localStorage.getItem("common"))[commonFind]

		if (commonFind == 'shijianduan') {
			if (Array.isArray(asdf)) {
				for (let s of asdf) {
					s.text = s.startTime + "-" + s.outTime
					s.value = s.id
				}
			}
		}

		return asdf;
	} catch (e) {
		uni.showToast({
			title: "数据异常"
		})
	}

}

/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 存储common 中的常用数
 * @param commonFind 字段
 * @param data 数据
 * @returns {void|*}
 */
export function setcommon(commonFind, data) {


	try {

		let common = JSON.parse(localStorage.getItem("common"))

		if (isNull(common)) {
			common = {}
		}

		common[commonFind] = data

		localStorage.setItem("common", JSON.stringify(common));
	} catch (e) {
		return null
	}

}



/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description 存储common 中的常用数
 * @param commonFind 字段
 * @param data 数据
 * @returns {void|*}
 */
export function clear() {
	console.log("清除缓存");
	localStorage.removeItem("common")

}